// src/hooks/useTheme.js
import { useState, useEffect } from 'react';

export default function useTheme() {
    const [darkMode, setDarkMode] = useState(() => {
      const savedTheme = localStorage.getItem('theme');
      return savedTheme === 'dark'; // 直接判断是否为dark
    });
  
    useEffect(() => {
      const html = document.documentElement;
      html.classList.toggle('dark', darkMode);
      localStorage.setItem('theme', darkMode ? 'dark' : 'light');
    }, [darkMode]);
  
    return [darkMode, setDarkMode];
  }